class Node:
    def __init__(self, data):
        # 初始化节点类，包含节点数据和下一节点的指针
        self.data = data  # 数据
        self.next = None  # 指针


class LinkList:
    def __init__(self):
        self.head = Node(None)

    def create(self, a):
        tail = self.head
        for i in range(len(a)):
            p = Node(a[i])
            tail.next = p
            tail = p

    def createrev(self, a):
        for i in range(len(a)):
            p = Node(a[i])
            p.next = self.head.next
            self.head.next = p

    def output(self):
        p = self.head.next
        cnt = 0
        while p != None:
            cnt += 1
            if cnt > 1:
                print(' ', end='')
            print(p.data, end='')
            p = p.next
        print()

    def search(self, x):
        # 查找特定元素x是否在元素中
        p = self.head.next
        flag = False
        while p.next != None:
            if p.data == x:
                flag = True
                break
            p = p.next
        return flag

    def insert(self, i, x):
        # 指定位置i插入元素x
        p = self.head
        while i > 1 and p != None:
            p = p.next
            i -= 1
            if i < 1 or p == None:
                return
            q = Node(x)
            q.next = p.next
            p.next = q

    def delete(self, x):
        # 删除特定元素x
        p = self.head.next
        q = self.head
        while p.next != None:
            if p.data == x:
                break
            q = p
            p = p.next
        q.next = p.next


a = [1, 23, 1, 53, 26, 453, 2345, 13653, 4, 512, 423, 453, 4253, 245, 32]
h = LinkList()
h.createrev(a)
h.output()
h = LinkList()
h.create(a)
h.output()
